package myJs.user

import myJs.Implicits._
import myJs.Utils._
import scala.scalajs.js.Dynamic.{global=>g}
import myJs.myPkg.DistpickerOptions
import myJs.myPkg.jquery._
import myJs.tool.Tool
import myJs.tool.Tool._
import org.scalajs.dom.ext.Ajax
import scalatags.Text.all.s

import org.scalajs.macrotaskexecutor.MacrotaskExecutor.Implicits._
import scala.scalajs.js
import scala.scalajs.js.annotation.{JSExport, JSExportTopLevel}

/**
 * Created by yz on 2019/4/25
 */
@JSExportTopLevel("SecuritySet")
object SecuritySet {

  @JSExport("init")
  def init = {
    refreshPersonInfo

  }

  def refreshPersonInfo = {
    val url = g.jsRoutes.controllers.UserController.getUserById().url.toString
    Ajax.get(url = s"${url.noCache}&id=${getId}", headers = Map("Content-Type" -> "application/json")).map { xhr =>
      val rs = xhr.responseText.toJDJAn.toMyJDS
      rs.foreach { case (k, v) =>
        $(s"span[id='${k}']").text(v)
      }
    }
  }

  def getId = {
    g.id.toString
  }

}
